package com.twu.biblioteca;

import java.util.List;
import java.util.Map;

/**
 * Created by sravanns on 19/06/14.
 */
public class ListCheckedOutMovies implements MenuAction {
    private Library library;
    private UserInterface userInterface;
    public ListCheckedOutMovies(Library library, UIApplication uiApplication) {
        this.library=library;
        this.userInterface=uiApplication;
    }


    @Override
    public String toString() {
        return "List checked out movies";
    }




        @Override
        public Result performAction(String user) throws InterruptedException {
            Result result=new Result();
            Map<String,List<Movie>> checkedList= library.getCheckedOutMovies();
            if(checkedList.size()==0)
            {
                result.setResult("no movies checked out",false);
                return result;
            }
            for(String person: checkedList.keySet())
            {
                userInterface.display("*******\nUser  "+person+"\n Movies checked out:");
                userInterface.displayBooks(checkedList.get(person));
                userInterface.display("\n*******");
            }
            result.setResult("listed "+checkedList.size()+" movies",true);
            return result;
        }


}
